<%@ page import="com.qf.pojo.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: glls
  Date: 2022/3/29
  Time: 16:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>jstl标签库</title>
</head>
<body>
    <p>
        1. 导入依赖 <br>
        2. 在页面  使用 taglib 指令  引入库
    </p>

    <p>
       1. &lt;c:if test ="条件"&gt; &lt; /c:if&gt;
    </p>

    <!-- test属性中是条件，但是条件需要使用EL表达式来书写 -->
    <h3>条件标签：if</h3>
    <c:if test="${8>2 }">
        8大于2是成立的
    </c:if>
    <c:if test="${8<2 }">
        8小于2是成立的
    </c:if>

    <%
        request.setAttribute("name","zs");
    %>
    <br>
    ${empty name ?"请登录":"欢迎你"} ${name}
    <c:if test="${empty name}">
        请登录
    </c:if>
    <c:if test="${! empty name}">
        欢迎你 ${name}
    </c:if>


    <h3>条件标签：choose(等价于java中多重if)</h3>
    <%-- 测试成绩等级 >90 优秀   >80  良好    >70 中等   >60及格--%>

<%--    默认放在 pageContext 域对象中--%>
    <c:set var="score" value="80" ></c:set>

<%--    ${pageScope.score}--%>
    <c:choose>
        <c:when test="${score>=90 }">优秀</c:when>
        <c:when test="${score>=80 }">良好</c:when>
        <c:when test="${score>=70 }">中等</c:when>
        <c:when test="${score>=60 }">及格</c:when>
        <c:otherwise>不及格</c:otherwise>
    </c:choose>

    <hr>
    <%
        List<Student> students = new ArrayList<>();

        students.add(new Student("zs",18));
        students.add(new Student("ls",19));
        students.add(new Student("ww",20));
        students.add(new Student("zl",20));
        students.add(new Student("tq",20));


        request.setAttribute("students",students);
    %>

    <c:forEach items="${students}" var="stu">
        ${stu.name}  ${stu.age}   ${stu.address.city}
    </c:forEach>


    <table>
        <tr>
            <th>
                编号
            </th>
            <th>
                姓名
            </th>
            <th>
                年龄
            </th>
        </tr>
<%--        <c:forEach items="${students}" var="stu" begin="0" end="4" step="2">--%>
        <c:forEach items="${students}" var="stu" varStatus="status">
            <tr>
                <td>
                    ${status.first}:${status.index + 1}:${status.count}
                </td>
                <td>
                    ${stu.name}
                </td>
                <td>
                    ${stu.age}
                </td>
            </tr>
        </c:forEach>
    </table>

<hr>

    <form action="${pageContext.request.contextPath}/xxx" method="post">
        <input type="submit" value="提交1">

    </form>


    <form action="<c:url context='/${pageContext.request.contextPath}' value="/request1"  />">
        <input type="submit" value="提交2">
    </form>


    <%
        String id = session.getId();

        // 重写url 拼接 sessionid
        String newurl = response.encodeRedirectURL("/xxx/x?sessionId=" + id);

        System.out.println(newurl);
    %>
</body>
</html>
